define(function() {
    return ['$scope','$location', '$interval','$timeout','$route','bizProxy', function($scope,$location,$interval,$timeout,$route,bizProxy) {
		$scope.$emit("top-show",'true');//顶部显示
    	$scope.$emit('menuTypeLight','mine'); 	//控制底部menu高亮
    	$scope.$emit('bub-menu','true'); 	//隐藏底部menu
    	$scope.$emit('flag-tag','12');//显示底部文字
    	
    	//默认值
    	$scope.isslide_left = false,$scope.allSlt = false,$scope.isSlide_up = false;
    	var tempCaseData = new Array();
    	
    	//点击状态进入详情
    	$scope.goCaseProfile = function(id){
    		if(id != "" && id != null){
    			caseDetailInfo(id);
    		}
    	}
    	
    	//点击选中某个
    	$scope.selectalone = function(index){
    		if(tempCaseData[index].slt){
    			tempCaseData[index].slt = false;
    		}else{
    			tempCaseData[index].slt = true;
    		}
    		$scope.tempCaseList = tempCaseData;
    	}
    	
    	//点击选中所有事件
    	$scope.selectAll = function(){
    		if($scope.allSlt){
    			$scope.allSlt = false;
    			tempCaseData.forEach(function(value,index){
        			value.slt = false;
        		})
    		}else{
    			$scope.allSlt = true;
    			tempCaseData.forEach(function(value,index){
        			value.slt = true;
        		})
    		}
    		$scope.tempCaseList = tempCaseData;
    	}
    	
    	//点击选中删除所有事件
    	$scope.delAll = function(){
    		var idList = new Array();
    		for(var i=0;i<tempCaseData.length;i++){
    			if(tempCaseData[i].slt){
    				idList.push(tempCaseData[i].caseId);
    			}
    		}
    		if(idList.length > 0){
    			delCollectList(idList.toString());
    		}else{
    			$scope.$emit("promptAlertMsg","请选中要删除的案件");
    			$scope.$emit("showCollect",true);
    			$timeout(function(){
    				$scope.$emit("showCollect",false);
    			},transData.promptTime);
    		}
    	}
    	
    	
    	//监听删除收藏点击事件
    	$scope.$on('deleteCollectEvent', function(event,data){
    		if(data){
    			$scope.isslide_left = true;
    			$scope.isSlide_up = true;
    		}else{
    			$scope.isslide_left = false;
    			$scope.isSlide_up = false;
    		}
        });
    	
    	//点击显示案件概况
    	$scope.goCaseProfile = function(id){
    		if(id != "" && id != null){
    			caseDetailInfo(id);
    		}
    	}

        //案源详细信息
        function caseDetailInfo(id){
            $scope.$emit("loadingChange",true);
            var headerInfo = {},bizInfo = {};
            headerInfo.pageNum =  '';
            headerInfo.pageSize = '';
            headerInfo.sessionId = transData.sessionId;

            bizInfo.caseId = id;
            bizProxy.queryProxyBizData("queryCaseInfoDetail",headerInfo,bizInfo,
                function(tempData){
                    console.log(JSON.parse(tempData.body))
                    $timeout(function(){
                        $scope.$emit('loadingChange', false);
                        resultData.caseDetailData = "";
                        resultData.caseDetailData = JSON.parse(tempData.body);
                        $scope.$emit('goNext',"/caseProfile");
                    },0);
                },function(data){
                    $scope.$emit('loadingChange', false);
                    $scope.$emit("promptAlertMsg",data);
                    $scope.$emit("showCollect",true);
                    $timeout(function(){
                        $scope.$emit("showCollect",false);
                    },transData.promptTime);
                });

        }
    	
    	//点击删除收藏夹列表
    	function delCollectList(idList){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;
        	
        	bizInfo.operation = 'del';
        	bizInfo.favorType = 'case';
        	bizInfo.ids = idList;
        	console.log(bizInfo)
    		$scope.$emit("loadingChangeNav",true);
    		bizProxy.queryProxyBizData("favorManage",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
                        console.log(tempData)
		    			$scope.$emit("loadingChangeNav",false);
						$timeout(function(){
							$scope.$emit('flag-tag','12-2');//显示底部文字
							$route.reload();
						},0);
		    		},function(data){
                    console.log(data)
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChangeNav",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("loadingChangeNav",false);
								$scope.$emit("promptAlertMsg",data.errorMsg);
				    			$scope.$emit("showCollect",true);
				    			$timeout(function(){
				    				$scope.$emit("showCollect",false);
				    			},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit("loadingChangeNav",false);
							$scope.$emit("promptAlertMsg","连接超时");
			    			$scope.$emit("showCollect",true);
			    			$timeout(function(){
			    				$scope.$emit("showCollect",false);
			    			},transData.promptTime);
		    			}
		    		});
    	}
    	
    	
    	//获取收藏案件列表数据
    	(function(){
    		var headerInfo = {},bizInfo = {};
        	headerInfo.pageNum = '';
        	headerInfo.pageSize = '';
        	headerInfo.sessionId = transData.sessionId;

        	bizInfo.operation='query';
        	bizInfo.favorType='case';
        	$scope.$emit("loadingChangeNav",true);
        	bizProxy.queryProxyBizData("favorManage",headerInfo,bizInfo,
    				function(tempData){//SUCCESS
						console.log(tempData)
        				$scope.$emit("loadingChangeNav",false);
		        		$timeout(function(){
							try{
								tempCaseData = new Array();
								var tempList = JSON.parse(tempData.body).favorCaseList;
								if(tempList.length===0){
									$scope.$emit('flag-tag','12-1');//显示底部文字
									$scope.tempCaseList = "";
									$scope.promptSlogan = true;
								}else{
									for(var i=0;i< tempList.length;i++){
										var tempData1 = {
												"caseId": tempList[i].caseId,
												"status": tempList[i].status,
												"creditorName":tempList[i].creditorName,
												"debtorName":tempList[i].debtorName,
												"caseAmt":tempList[i].caseAmt,
												"slt":false
										};
										tempCaseData.push(tempData1);
									}
									$scope.tempCaseList = tempCaseData;
								}
								
							}catch(e){
								$scope.$emit('flag-tag','12-1');//显示底部文字
								$scope.tempCaseList = "";
								$scope.promptSlogan = true;
							}
						},0);
		    		},function(data){
    					console.log(data)
		    			if(data != ""){//FAIL
		    				$scope.$emit("loadingChangeNav",false);
							if(data.errorCode == ERROR_CODE.noLogin){
								FIREFLY("", data.errorMsg,"",function(){
										//调用退出登录
										transData.mobileNo = "";
		    							transData.password = "";
		    							transData.sessionId = "";
		    							transData.userType = "";
		    							resultData.loginUserData = "";
		    							$timeout(function(){
		    								$scope.$emit("goNext","/mine");
		    							},0);
								});
							}else{
								$scope.$emit("loadingChangeNav",false);
								$scope.$emit("promptAlertMsg",data.errorMsg);
								$scope.$emit("showCollect",true);
								$timeout(function(){
									$scope.$emit("showCollect",false);
								},transData.promptTime);
							}
		    			}else{
		    				$scope.$emit("loadingChangeNav",false);
							$scope.$emit("promptAlertMsg","连接超时");
							$scope.$emit("showCollect",true);
							$timeout(function(){
								$scope.$emit("showCollect",false);
							},transData.promptTime);
		    			}
		    		});
    	}()); 
        $scope.$apply();
    }];
});